<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
    <title>Title</title>
</head>
<body>

<form action="${pageContext.request.contextPath}/findCond" method="post">

    <p style="text-align: center">
        姓名: <input type="text" name="username" size="25px" value="${param.username}"/>
        性别:
        <input type="radio" name="gender" value="nan"
               ${param.gender == 'nan'?'checked':''}
        />男
        <input type="radio" name="gender" value="nv"
        ${param.gender == 'nv'?'checked':''}
        />女
        <input type="radio" name="gender" value=""
        ${ empty param.gender ?'checked':''}
        />男女都查

        城市:
        <select name="city">
            <option value="" ${param.city == ''?'selected':''}>无</option>
            <option value="shijiazhuang"
                    ${param.city == 'shijiazhuang'?'selected':''}
            >石家庄</option>
            <option value="beijing"
            ${param.city == 'beijing'?'selected':''}
            >北京</option>
            <option value="shanghai"
            ${param.city == 'shanghai'?'selected':''}
            >上海</option>
            <option value="newYork"
            ${param.city == 'newYork'?'selected':''}
            >纽约</option>
        </select>

        <input type="submit" value="条件查询">


    </p>
</form>
<form action="${pageContext.request.contextPath}/delBatch" method="post">
    <table border="1" cellspacing="0" cellpadding="10" align="center">

        <tr>
            <th> <input type="checkbox">全选 </th>
            <th>id</th>
            <th>用户名</th>
            <th>性别</th>
            <th>爱好</th>
            <th>城市</th>
            <th>介绍</th>
            <th>操作</th>
        </tr>

       <c:forEach items="${requestScope.list}" var="user" varStatus="stat">
           <tr>
               <td class="tt"> <input type="checkbox" name="ids" value="${user.id}"/>  </td>
               <td>${stat.index + 1}</td>
               <td>${user.username}</td>
               <td>${user.gender}</td>
               <td>${user.hobby}</td>
               <td>${user.city}</td>
               <td> <c:out value="${user.introduce}"/> </td>
               <td>
                       <%-- <a href="/day06/delUser?id=<%=user.getId()%>">删除</a>--%>
                       <%--<button onclick="shanchu(<%=user.getId()%>)">删除</button>
                          <button onclick="xiugai(<%=user.getId()%>)">修改</button>--%>

                  <input  onclick="shanchu(${user.id})" type="button" value="删除"/>
                               <input  onclick="xiugai(${user.id})" type="button" value="修改"/>
               </td>
           </tr>
       </c:forEach>
    </table>

    <p style="text-align: center"> <input type="submit" value="批量删除"/> </p>
</form>

</body>

<script>
    function shanchu(id) {
        var isShan = confirm("您确定要删除这条数据吗?");
        if(isShan){
            location.href = "${pageContext.request.contextPath}/delUser?id="+id;
        }
    }

    function xiugai(id) {
        //首先 携带者 id,跳转到一个 servlet,根据id查询用户, 存入reequest域,转发到jsp界面
        location.href = "${pageContext.request.contextPath}/findUser?id="+id;
    }
</script>

<script type="text/javascript" src="js/jquery-1.12.4.min.js">
</script>

<script type="text/javascript">

    $("th input").click(function(){
        $(".tt input").prop("checked",$(this).prop("checked"));
    })


    $(".tt input").click(function(){
        $("th input").prop("checked",$(".tt input").length == $(".tt input:checked").length)
    })

</script>
</html>
